package com.ftg.learn.course.config;

import com.ftg.learn.course.properties.Knife4jProperties;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author LY
 */
@Configuration
@RequiredArgsConstructor
public class Knife4jConfiguration {
    @Autowired
    private final Knife4jProperties knife4jProperties;
    @Bean
    public OpenAPI codeApi() {
        return new OpenAPI()
                .info(new Info()
                        .title(knife4jProperties.getTitle())
                        .description(knife4jProperties.getDescription())
                        .termsOfService(knife4jProperties.getTermsOfService())
                        .contact(new Contact().name(knife4jProperties.getContactName()).url(knife4jProperties.getContactUrl()).email(knife4jProperties.getContactEmail()))
                        .license(new License().name(knife4jProperties.getLicenseName()).url(knife4jProperties.getLicenseUrl()))
                        .version(knife4jProperties.getVersion())
                );
    }
}
